#!/usr/bin/env node
const program = require('commander');
const tabIndent = require("./tabIndent");


program.version('0.0.1')
	.usage('[options] filePath')
	.option('-i, --spaces <n>', '缩进空格数')
	.option('-e, --fileExt <n>', '扩展名')
	.option('-c, --charset <n>', '字符编码')
	.parse( process.argv );

program.spaces = program.spaces || 4 ;
program.fileExt = program.fileExt || "js";
main().catch( err =>
	console.error( err )
);

async function main(  ){
	let path = program.args[0];
	console.info( path );
	if( !path ){
		console.info( "请输入文件路径");
		return;
	}
	if( !( program.spaces>1 && program.spaces<8 ) )
		throw new Error("缩进空格数只允许2-8 ,输入的是:" + program.spaces );
	console.info( program );
	let files = await tabIndent( path , program );
	console.info( "总共格式化了"+ files.length +"个文件");
}
